<template>
  <div class="body">
    <div class="back">
      <span class="span1"></span>
      <span class="span2"></span>
      <span class="span3"></span>
      <span class="span4"></span>
      <span class="span5"></span>
      <span class="span6"></span>
      <span class="span7"></span>
      <span class="span8"></span>
      <!-- <span class="span9"></span>
      <span class="span10"></span> -->
      <el-form v-show="showon" class="form" label-position="left" :model="form" :rules="rules" ref="form">
        <h3 class="title">Administrator Login</h3>
        <el-form-item prop="username">
          <el-input v-model="form.username" placeholder="请输入管理员账号"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="form.password" type="password" placeholder="请输入管理员密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width: 100%" @click="onSubmit()">登录</el-button>
        </el-form-item>
      </el-form>
      <div class="card" @click="login" v-show="!showon">
        <h3>勇士!
          <br>
          打开我,将翻开典藏的秘密</h3>
        <h4>--我们发飙了</h4>
      </div>
    </div>




  </div>
</template>

<script>
import httpApi from '@/http';
import { mapMutations } from 'vuex';

export default {
  data() {
    return {
      showon: false,
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请填写用户名", trigger: "blur" },
          {
            pattern: /^\w{3,15}$/,
            message: "3~15位字符，可以包含：数字、字母、下划线",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请填写用户名", trigger: "blur" },
          {
            pattern: /^\w{6,15}$/,
            message: "6~15位字符，可以包含：数字、字母、下划线",
            trigger: "blur",
          },
        ],
      },
    };
  },

  methods: {
    // 将会实现使用  
    // this.saveUser(1) 代替 this.$store.commit('saveUser', 1)
    ...mapMutations(['saveToken', 'saveUser', 'saveMenu']),

    login() {
      this.showon = true
    },
    onSubmit() {
      // 发送登录请求 
      this.$refs.form.validate(valid => {
        if (valid) { // 通过了表单验证
          let params = {
            user: this.form.username,
            pwd: this.form.password,
            // username: this.form.username,
            // password: this.form.password,
          }
          httpApi.adminApi.login(params).then(res => {
            console.log('登录结果', res)
            if (res.data == '错误次数大于3') {
              this.$message.error('登录失败,密码错误超过3次,24小时后再试');
              // this.$alert(`登录失败,密码错误超过3次,今日不可再登录`, '限制登录', {
              //   confirmButtonText: '确定',
              //   callback: action => {
              //     this.$message({
              //       type: 'info',
              //       message: '请24小时后重置'
              //     });
              //   }
              // });
            } else {
              if (res.data.code == 200) {
                // 将结果存储在vueX中
                this.saveUser(res.data.data.user);
                this.saveMenu(res.data.data.menu);
                // 将token存储在vuex  方便登录之后才能申请网络请求
                this.saveToken(res.data.data.token);
                // 将token存入vuex
                this.$router.push("/home/index");
              }
            }
            if (res.data.code == 1001) {
              this.$message({
                message: `登录失败,错误次数:${res.data.errorcount}次,3次之后不能登录`,
                type: 'warning'
              });
              // this.$alert(`登录失败,错误次数:${res.data.errorcount}次,3次之后不能登录`, '密码错误', {
              //   confirmButtonText: '确定',
              //   callback: action => {
              //     this.$message({
              //       type: 'info',
              //       message: '请重新登录'
              //     });
              //   }
              // });
            }

          })
        }
      })
    },
  },
};
</script>

<style scoped>
.back .card {
  display: block;
  position: absolute;
  top: 40%;
  left: 50%;
  width: 30%;
  height: 40%;
  transform: translate(-50%,-50%);
  /* box-shadow: inset 300px 0 50px rgba(0, 0, 0, 0.5); */
  transition: 0.8s;
  transform-style: preserve-3d;
  /* border: 4px solid #6d2881; */
}
.card h3{
  display: block;
  margin: 30% 0 0 30%;
}
.card h4{
  display: block;
  margin: 20% 0 0 50%;
}
.form {
  display: block;
  width: 20%;
  position: absolute;
  top: 30%;
  left: 40%;
}

.form .title {
  text-align: center;
  font-size: 1.5em;
  color: white;
  margin-bottom: 20px;
}

.back {
  overflow: hidden;
  height: 100vh;
  /* background-image: linear-gradient(125deg, #e14040, #b050cd, #4842c9, #34828d);
   */
  background-image: url(../../assets/bg11.jpg);
  background-size: 150%;
  animation: animate 100s infinite;
  position: relative;
}

@keyframes animate {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

/* 动画方法 */
@keyframes anistar {
  0% {
    transform: rotate(315deg) translateX(0);
    opacity: 1;
  }

  70% {
    opacity: 0.8;
  }

  100% {
    transform: rotate(315deg) translateX(-1000px);
    opacity: 0.2;
  }
}

.back span:before {
  content: '';
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 300px;
  height: 1px;
  background: linear-gradient(90deg, #f409fcab, transparent);
}

.back>.span1 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 3.5s linear infinite;
}

.back>.span2 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 10%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 6s linear infinite;
  animation-delay: 0.2s;
  animation-duration: 1.8s;
}

.back>.span3 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: -20%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 6s linear infinite;
  animation-delay: 0.5s;
  animation-duration: 3s;
}

.back>.span4 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 20%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 6s linear infinite;
  animation-delay: 0.8s;
  animation-duration: 5s;
}

.back>.span5 {
  position: absolute;
  z-index: 1;
  top: 10%;
  right: 40%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 4s linear infinite;
  animation-delay: 0.6s;
  animation-duration: 5s;
}

.back>.span6 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 80%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 6s linear infinite;
  animation-delay: 0.5s;
  animation-duration: 3s;
}

.back>.span7 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: -30%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 10s linear infinite;
  animation-delay: 0.3s;
  animation-duration: 3.5s;
}

.back>.span8 {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 60%;
  left: initial;
  width: 4px;
  height: 4px;
  background: #ff22ff;
  background-image: linear-gradient(226deg, #6374a0, #65a7b1 69%, #70645f);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(255, 151, 241, 0.1),
    0 0 0 8px rgba(255, 129, 255, 0.1),
    0 0 20px rgb(2476, 34, 253);
  animation: anistar 4s linear infinite;
  animation-delay: 1s;
  animation-duration: 4s;
}</style>


